
<?php
//模块插件类
//对外接口函数类，其他插件可通过“$this->plugin('模块名称')->方法名” 来调用本类的方法
defined('BY_JYA') or exit('error');
class func_jy_hanwangapi extends plugin{
	public function hw($sf,$face){
		$setting=$this->get_setting($postdata);
		$host = "http://face2idcard.aliapi.hanvon.com";
		$path = "/rt/ws/v1/face/faceid/recg";
		$method = "POST";
		$appcode = $setting['appcode'];
		$headers = array();
		array_push($headers, "Authorization:APPCODE " . $appcode);
		array_push($headers, "Content-Type".":"."application/octet-stream");
		//根据API的要求，定义相对应的Content-Type
		array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
		$querys = "code=1b88a702-7a32-4443-a146-9919c9474cc9";
		$uid=$_SERVER['HTTP_HOST'];
		$idcardImage=base64_encode(file_get_contents($sf));
		$faceImage=base64_encode(file_get_contents($face));
		$bodys=array('uid'=>$uid,'idcardImage'=>$idcardImage,'faceImage'=>$faceImage);
		$bodys =json_encode($bodys);
		$url = $host . $path . "?" . $querys;

		$curl = curl_init();
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($curl, CURLOPT_FAILONERROR, false);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_HEADER, true);
		if (1 == strpos("$".$host, "https://"))
		{
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
		}
		curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
		 $result = curl_exec($curl);
		 $result=json_decode($result,true);
		 if($result['result']=='success'){
			 return $result['score'];
		 }else{
			 return $result['result'];
		 }
	}
}
?>
